package 力扣日常刷题.木22一月.第10天0118;

import java.util.Arrays;
import java.util.List;

/**
 * @author 帅小伙
 * @date 2022/1/18
 * @description
 */
public class Demo14每日一题中等最小时间差 {


    public int findMinDifference(List<String> timePoints) {
        int ans = Integer.MAX_VALUE;;
        int[] times = new int[timePoints.size()];
        for (int i = 0; i < timePoints.size(); i++) {
            String[] split = timePoints.get(i).split(":");
            times[i] = new Integer(split[0]) * 60 + new Integer(split[1]);
        }
        Arrays.sort(times);

        for (int i = 0; i < times.length - 1; i++) {
            if (ans > times[i + 1] - times[i]) {
                ans = times[i + 1] - times[i];
            }
        }
        ans = Math.min(ans,(24*60-times[times.length-1])+times[0]);
        return ans;
    }
}
